<template>
  <a-dropdown placement="bottomRight">

    <span class="ant-pro-account-avatar">
      	<a-avatar style="width: 32px;height: 32px;" size="small"
                  :src="currentUser.avatarUrl"
				class="antd-pro-global-header-index-avatar" />
 
      <span v-if="currentUser" style="color: #555">{{ currentUser.name }}</span>
      <span style="color: #555" v-if="!currentUser">你好，用户</span>
      <a-icon
        type="caret-down"
        style="margin-left: 10px;"
      />
    </span>

    <template v-slot:overlay>
      <a-menu class="ant-pro-drop-down menu">
        <a-menu-item
          key="logout"
          @click="handleLogout"
        >
          退出登录
        </a-menu-item>
      </a-menu>
    </template>

  </a-dropdown>
  <!-- <span v-else>
    <a-spin
      size="small"
      :style="{ marginLeft: 8, marginRight: 8 }"
    />
  </span> -->
</template>

<script>
import { Modal } from "ant-design-vue";

export default {
  name: "AvatarDropdown",
  props: {
    currentUser: {
      type: Object,
      default: () => null,
    },
    menu: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {};
  },
  mounted() {},
  methods: {
    handleToCenter() {
      this.$router.push({
        path: "/account/center",
      });
    },
    handleToSettings() {
      this.$router.push({
        path: "/account/settings",
      });
    },
    handleLogout(e) {
      Modal.confirm({
        title: this.$t('提示'),
        content: this.$t("您确定要注销吗？"),
        okText:'确定',
        cancelText:'取消',
        onOk: () => {
          // return new Promise((resolve, reject) => {
          //   setTimeout(Math.random() > 0.5 ? resolve : reject, 1500)
          // }).catch(() => console.log('Oops errors!'))
          return this.$store.dispatch("Logout").then(() => {
            this.$router.push({
              name: "login",
            });
          });
        },
        onCancel() {},
      });
    },
    jump(val) {
      if (val == "updatepassword") {
        this.$router.push({
          path: "/updatepassword",
        });
      } else if (val == "menu") {
        this.$router.push({
          path: "/",
        });
      }
    },
  },
};
</script>

<style lang="less" scoped>
.ant-pro-drop-down {
  /deep/ .action {
    margin-right: 8px;
  }

  /deep/ .ant-dropdown-menu-item {
    // min-width: 160px;
  }
}

.ant-pro-account-avatar {
  color: #c9def8;
  line-height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;

  .no-img {
    display: inline-block;
    width: 35px;
    height: 35px;
    border: 1px solid #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    margin-right: 14px;
  }
}
</style>
